import request from '@/utils/request'
//获取操作指令
export function getCourseActionInstruct(params) {
  return request({
    url: 'course/obtain/course_info',
    method: 'get',
    params
  })
}
//生成或修改课程信息
// sport
// string
// 是
// 运动id
// course
// string
// 是
// 课程id
// courseDetails
// string
// 是
// 课程信息id
// actionInstru
//lesson
export function addEdit(course = 'course', params) {
  return request({
    url: 'course/manager/generate/'+ course,
    method: 'post',
    params
  })
}

// 修改日程信息 更新课程信息
export function updateInfo(course = 'course', params,data) {
  return request({
    url: 'course/manager/update/' + course,
    method: 'post',
    params,
    data,
    transformRequest: [function (data) {
      let  formData;
      if ( !data ) {
        formData = data
      } else {
        formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      }
      return formData
    }]
  })
}

// 修改日程信息 更新课程信息
export function copyInfo(course = 'course', params,data) {
  return request({
    url: '/course/copy/' + course,
    method: 'post',
    params,
    data,
    transformRequest: [function (data) {
      let  formData;
      if ( !data ) {
        formData = data
      } else {
        formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      }
      return formData
    }]
  })
}

export function delInfo(course = 'course', params) {
  return request({
    url: 'course/manager/del/' + course,
    method: 'post',
    params

  })
}

export function getTypeCodeList(params) {
  return request({
    url: '/setting/type/query_code',
    method: 'get',
    params
  })
}
//日程列表
export function getTrainList(url, params) {
  return request({
    url: url,
    method: 'get',
    params
  })
}



export  function  asyncGet(url, method='get', params,data) {
  return  new Promise((resolve, reject) =>request({
    url,
    method,
    params,
    data,
    _transformRequest:true
  }).then((response)=>resolve(response)).catch(error=>reject(error)))
}

export  async function  getNot_athletesList(athletes='athletes',params) {
  return new Promise((resolve, reject) =>request({
    url: 'setting/query/'+athletes,
    method: 'post',
    params
  }).then((response)=>resolve(response)).catch(error=>reject(error)))
}




export const getTrainInfo = {

    "status": 0,
    "msg": "SUCCESS",
    "result": {
        "lesson": {

        },
        "coachList": [

        ],
        "athleteList": []
        }
}


export function addTrain(url, params) {
  return request({
    url: url,
    method: 'post',
    data: params,
    transformRequest: [function (data) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}


export function modifyTrain(url, params) {
  return request({
    url: url,
    method: 'post',
    data: params,
    transformRequest: [function (data) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}

export function placeTrain(url, params) {
  return request({
    url: url,
    method: 'get',
    params
  })
}
